

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Pre-Processing Exporter &mdash; Nyoka 4.2.0 documentation</title>
  

  
  
  
  

  
  <script type="text/javascript" src="../_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript">
          var DOCUMENTATION_OPTIONS = {
              URL_ROOT:'../',
              VERSION:'4.2.0',
              LANGUAGE:'None',
              COLLAPSE_INDEX:false,
              FILE_SUFFIX:'.html',
              HAS_SOURCE:  true,
              SOURCELINK_SUFFIX: '.txt'
          };
      </script>
        <script type="text/javascript" src="../_static/jquery.js"></script>
        <script type="text/javascript" src="../_static/underscore.js"></script>
        <script type="text/javascript" src="../_static/doctools.js"></script>
    
    <script type="text/javascript" src="../_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../index.html" class="icon icon-home"> Nyoka
          

          
          </a>

          
            
            
              <div class="version">
                4.2
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul>
                <li class="toctree-l1"><a class="reference internal" href="../statsmodels_to_pmml.html">Statsmodels Exporter Module</a></li>
                <li class="toctree-l1"><a class="reference internal" href="../keras_model_to_pmml.html">Keras Exporter Module</a></li>
                <li class="toctree-l1"><a class="reference internal" href="../retinanet.html">RetinaNet Exporter Module</a></li>
                <li class="toctree-l1"><a class="reference internal" href="../lgb_to_pmml.html">LightGBM Exporter Module</a></li>
                <li class="toctree-l1"><a class="reference internal" href="../pre_process.html">Pre-Processing Exporter Module</a></li>
                <li class="toctree-l1"><a class="reference internal" href="../skl_to_pmml.html">Scikit-Learn Exporter Module</a></li>
                <li class="toctree-l1"><a class="reference internal" href="../xgboost_to_pmml.html">XGBoost Exporter Module</a></li>
                <li class="toctree-l1"><a class="reference internal" href="../exponential_smoothing.html">ExponentialSmoothing Exporter Module</a></li>
                <li class="toctree-l1"><a class="reference internal" href="../preprocess_nyoka.html">Nyoka's Pre-Processing Module</a></li>
                <li class="toctree-l1"><a class="reference internal" href="../enums.html">Enums Module</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">Nyoka</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../index.html">Docs</a> &raquo;</li>
        
          <li><a href="index.html">Module code</a> &raquo;</li>
        
      <li>Pre-Processing Exporter</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for Pre-Processing Exporter</h1><div class="highlight"><pre>
<span></span><span class="kn">from</span> <span class="nn">__future__</span> <span class="k">import</span> <span class="n">absolute_import</span>
<span class="kn">import</span> <span class="nn">sys</span><span class="o">,</span> <span class="nn">os</span>

<span class="n">BASE_DIR</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="vm">__file__</span><span class="p">))</span>
<span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">BASE_DIR</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">PMML44</span> <span class="k">as</span> <span class="nn">pml</span>
<span class="kn">from</span> <span class="nn">enums</span> <span class="k">import</span> <span class="o">*</span>
<span class="n">exception_cols</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>

<div class="viewcode-block" id="get_preprocess_val"><span class="k">def</span> <span class="nf">get_preprocess_val</span><span class="p">(</span><span class="n">ppln_sans_predictor</span><span class="p">,</span> <span class="n">initial_colnames</span><span class="p">,</span> <span class="n">model</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Generates elements related to pre-processing</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    model :</span>
<span class="sd">        Contains an instance of Sklearn model</span>
<span class="sd">    ppln_sans_predictor :</span>
<span class="sd">        Contains an instance of Sklearn Pipeline</span>
<span class="sd">    initial_colnames : list</span>
<span class="sd">        Contains list of feature/column names.</span>

<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    pml_pp: dictionary</span>
<span class="sd">        Returns a dictionary that contains data related to pre-processing</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">pml_pp</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
    <span class="n">pml_derived_flds</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
    <span class="n">initial_colnames</span> <span class="o">=</span> <span class="p">[</span><span class="n">col_name</span> <span class="k">for</span> <span class="n">col_name</span> <span class="ow">in</span> <span class="n">initial_colnames</span><span class="p">]</span>
    <span class="n">updated_colnames</span> <span class="o">=</span> <span class="n">initial_colnames</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
    <span class="n">dtd_feat_names</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
    <span class="n">classes</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
    <span class="n">class_attribute</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
    <span class="n">mining_strategy</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
    <span class="n">mining_replacement_val</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
    <span class="n">mining_attributes</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
    <span class="n">pml_trfm_dict</span> <span class="o">=</span> <span class="kc">None</span>
    <span class="n">polynomial_features</span><span class="o">.</span><span class="n">poly_ctr</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="n">pca</span><span class="o">.</span><span class="n">counter</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="n">imputer</span><span class="o">.</span><span class="n">col_names</span> <span class="o">=</span> <span class="n">initial_colnames</span>

    <span class="k">for</span> <span class="n">ppln_step</span> <span class="ow">in</span> <span class="n">ppln_sans_predictor</span><span class="p">:</span>
        <span class="n">ppln_step_inst</span> <span class="o">=</span> <span class="n">ppln_step</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
        <span class="k">if</span> <span class="s2">&quot;DataFrameMapper&quot;</span> <span class="o">==</span> <span class="n">get_class_name</span><span class="p">(</span><span class="n">ppln_step_inst</span><span class="p">):</span>
            <span class="n">dfm_steps</span> <span class="o">=</span> <span class="n">ppln_step_inst</span><span class="o">.</span><span class="n">features</span>
            <span class="n">dfm_col_names</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">dfm_step</span> <span class="ow">in</span> <span class="n">dfm_steps</span><span class="p">:</span>
                <span class="n">dfm_step_col_names</span> <span class="o">=</span> <span class="n">dfm_step</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
                <span class="n">dfm_step_trfms</span> <span class="o">=</span> <span class="n">dfm_step</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">dfm_step_trfms</span><span class="p">:</span>
                    <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">dfm_step_col_names</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">col</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">dtd_feat_names</span><span class="p">:</span>
                            <span class="n">dtd_feat_names</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">col</span><span class="p">)</span>
                    <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">dfm_step_col_names</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">col</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">dfm_col_names</span><span class="p">:</span>
                            <span class="n">dfm_col_names</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">col</span><span class="p">)</span>
                    <span class="k">continue</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">dfm_step_col_names</span><span class="p">,</span> <span class="s2">&quot;__len__&quot;</span><span class="p">)</span> <span class="ow">or</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dfm_step_col_names</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
                    <span class="n">dfm_step_col_names</span> <span class="o">=</span> <span class="p">[</span><span class="n">dfm_step_col_names</span><span class="p">]</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">dfm_step_trfms</span><span class="p">,</span> <span class="s2">&quot;__len__&quot;</span><span class="p">)</span> <span class="ow">or</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dfm_step_trfms</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
                    <span class="n">dfm_step_trfms</span> <span class="o">=</span> <span class="p">[</span><span class="n">dfm_step_trfms</span><span class="p">]</span>
                <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">dfm_step_col_names</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">dtd_feat_names</span><span class="p">:</span>
                        <span class="n">dtd_feat_names</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>

                <span class="k">for</span> <span class="n">trfm</span> <span class="ow">in</span> <span class="n">dfm_step_trfms</span><span class="p">:</span>
                    <span class="n">pp_dict</span> <span class="o">=</span> <span class="n">get_pml_derived_flds</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">dfm_step_col_names</span><span class="p">,</span> <span class="n">model</span><span class="o">=</span><span class="n">model</span><span class="p">)</span>
                    <span class="n">derived_flds</span> <span class="o">=</span> <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_fld&#39;</span><span class="p">]</span>
                    <span class="n">derived_names</span> <span class="o">=</span> <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_col_names&#39;</span><span class="p">]</span>
                    <span class="k">if</span> <span class="s1">&#39;pp_feat_class_lbl&#39;</span> <span class="ow">in</span> <span class="n">pp_dict</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
                        <span class="n">classes</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;pp_feat_class_lbl&#39;</span><span class="p">])</span>
                        <span class="n">class_attribute</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;pp_feat_name&#39;</span><span class="p">])</span>
                    <span class="k">if</span> <span class="s1">&#39;pp_feat_class_ohe&#39;</span> <span class="ow">in</span> <span class="n">pp_dict</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
                        <span class="n">classes</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;pp_feat_class_ohe&#39;</span><span class="p">])</span>
                        <span class="n">class_attribute</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;pp_feat_name&#39;</span><span class="p">])</span>
                    <span class="k">if</span> <span class="s1">&#39;mining_strategy&#39;</span> <span class="ow">in</span> <span class="n">pp_dict</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
                        <span class="n">mining_attributes</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_col_names&#39;</span><span class="p">])</span>
                        <span class="n">mining_strategy</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;mining_strategy&#39;</span><span class="p">])</span>
                        <span class="n">mining_replacement_val</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;mining_replacement_val&#39;</span><span class="p">])</span>
                    <span class="n">pml_derived_flds</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">derived_flds</span><span class="p">)</span>
                    <span class="n">dfm_step_col_names</span> <span class="o">=</span> <span class="n">derived_names</span>
                <span class="n">dfm_col_names</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">derived_names</span><span class="p">)</span>

            <span class="n">updated_colnames</span> <span class="o">=</span> <span class="n">dfm_col_names</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">dtd_feat_names</span><span class="p">:</span>
                <span class="n">dtd_feat_names</span> <span class="o">=</span> <span class="n">initial_colnames</span>
                <span class="n">updated_colnames</span> <span class="o">=</span> <span class="n">initial_colnames</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">ppln_step_inst</span><span class="p">,</span> <span class="s2">&quot;__len__&quot;</span><span class="p">)</span> <span class="ow">or</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">ppln_step_inst</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
                <span class="n">ppln_step_inst</span> <span class="o">=</span> <span class="p">[</span><span class="n">ppln_step_inst</span><span class="p">]</span>
            <span class="k">for</span> <span class="n">trfm</span> <span class="ow">in</span> <span class="n">ppln_step_inst</span><span class="p">:</span>
                <span class="n">pp_dict</span> <span class="o">=</span> <span class="n">get_pml_derived_flds</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">updated_colnames</span><span class="p">,</span> <span class="n">model</span><span class="o">=</span><span class="n">model</span><span class="p">)</span>
                <span class="n">derived_flds</span> <span class="o">=</span> <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_fld&#39;</span><span class="p">]</span>
                <span class="n">derived_names</span> <span class="o">=</span> <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_col_names&#39;</span><span class="p">]</span>
                <span class="k">if</span> <span class="s1">&#39;pp_feat_class_lbl&#39;</span> <span class="ow">in</span> <span class="n">pp_dict</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
                    <span class="n">classes</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;pp_feat_class_lbl&#39;</span><span class="p">])</span>
                    <span class="n">class_attribute</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;pp_feat_name&#39;</span><span class="p">])</span>
                <span class="k">if</span> <span class="s1">&#39;pp_feat_class_ohe&#39;</span> <span class="ow">in</span> <span class="n">pp_dict</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
                    <span class="n">classes</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;pp_feat_class_ohe&#39;</span><span class="p">])</span>
                    <span class="n">class_attribute</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;pp_feat_name&#39;</span><span class="p">])</span>
                <span class="k">if</span> <span class="s1">&#39;mining_strategy&#39;</span> <span class="ow">in</span> <span class="n">pp_dict</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
                    <span class="n">mining_attributes</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_col_names&#39;</span><span class="p">])</span>
                    <span class="n">mining_strategy</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;mining_strategy&#39;</span><span class="p">])</span>
                    <span class="n">mining_replacement_val</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;mining_replacement_val&#39;</span><span class="p">])</span>
                <span class="n">pml_derived_flds</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">derived_flds</span><span class="p">)</span>
                <span class="n">updated_colnames</span> <span class="o">=</span> <span class="n">derived_names</span>

    <span class="k">if</span> <span class="n">pml_derived_flds</span><span class="p">:</span>
        <span class="n">pml_trfm_dict</span> <span class="o">=</span> <span class="n">pml</span><span class="o">.</span><span class="n">TransformationDictionary</span><span class="p">(</span><span class="n">DerivedField</span><span class="o">=</span><span class="n">pml_derived_flds</span><span class="p">)</span>

    <span class="n">pml_pp</span><span class="p">[</span><span class="s1">&#39;trfm_dict&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">pml_trfm_dict</span>
    <span class="n">pml_pp</span><span class="p">[</span><span class="s1">&#39;derived_col_names&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">updated_colnames</span>
    <span class="n">pml_pp</span><span class="p">[</span><span class="s1">&#39;preprocessed_col_names&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dtd_feat_names</span>
    <span class="n">pml_pp</span><span class="p">[</span><span class="s1">&#39;categorical_feat_values&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">classes</span><span class="p">,</span> <span class="n">class_attribute</span>
    <span class="n">pml_pp</span><span class="p">[</span><span class="s1">&#39;mining_imp_values&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">mining_attributes</span><span class="p">,</span> <span class="n">mining_strategy</span><span class="p">,</span> <span class="n">mining_replacement_val</span>

    <span class="k">return</span> <span class="n">pml_pp</span></div>


<div class="viewcode-block" id="get_class_name"><span class="k">def</span> <span class="nf">get_class_name</span><span class="p">(</span><span class="bp">cls</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Provides the class name for the given instance</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    cls :</span>
<span class="sd">        Contains the Sklearn&#39;s preprocessing instance</span>

<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">        Returns the class name of the pre-processed object.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="bp">cls</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span></div>


<div class="viewcode-block" id="get_pml_derived_flds"><span class="k">def</span> <span class="nf">get_pml_derived_flds</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">col_names</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Generates elements related to pre-processing for a given transformer object</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    trfm :</span>
<span class="sd">        Contains the Sklearn&#39;s preprocessing instance</span>
<span class="sd">    col_names : list</span>
<span class="sd">        Contains list of feature/column names.</span>
<span class="sd">        The column names may represent the names of preprocessed attributes.</span>

<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    pml_pp: dictionary</span>
<span class="sd">        Returns a dictionary that contains attributes related to any preprocessing function .</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">if</span> <span class="s2">&quot;StandardScaler&quot;</span> <span class="o">==</span> <span class="n">get_class_name</span><span class="p">(</span><span class="n">trfm</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">std_scaler</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">col_names</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
    <span class="k">elif</span> <span class="s2">&quot;MinMaxScaler&quot;</span> <span class="o">==</span> <span class="n">get_class_name</span><span class="p">(</span><span class="n">trfm</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">min_max_scaler</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">col_names</span><span class="p">)</span>
    <span class="k">elif</span> <span class="s2">&quot;RobustScaler&quot;</span> <span class="o">==</span> <span class="n">get_class_name</span><span class="p">(</span><span class="n">trfm</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">rbst_scaler</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">col_names</span><span class="p">)</span>
    <span class="k">elif</span> <span class="s2">&quot;MaxAbsScaler&quot;</span> <span class="o">==</span> <span class="n">get_class_name</span><span class="p">(</span><span class="n">trfm</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">max_abs_scaler</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">col_names</span><span class="p">)</span>
    <span class="k">elif</span> <span class="s2">&quot;TfidfVectorizer&quot;</span> <span class="o">==</span> <span class="n">get_class_name</span><span class="p">(</span><span class="n">trfm</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">tfidf_vectorizer</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">col_names</span><span class="p">)</span>
    <span class="k">elif</span> <span class="s2">&quot;CountVectorizer&quot;</span> <span class="o">==</span> <span class="n">get_class_name</span><span class="p">(</span><span class="n">trfm</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">count_vectorizer</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">col_names</span><span class="p">)</span>
    <span class="k">elif</span> <span class="s2">&quot;LabelEncoder&quot;</span> <span class="o">==</span> <span class="n">get_class_name</span><span class="p">(</span><span class="n">trfm</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">lbl_encoder</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">col_names</span><span class="p">)</span>
    <span class="k">elif</span> <span class="s2">&quot;Imputer&quot;</span> <span class="o">==</span> <span class="n">get_class_name</span><span class="p">(</span><span class="n">trfm</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">imputer</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">col_names</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
    <span class="k">elif</span> <span class="s2">&quot;Binarizer&quot;</span> <span class="o">==</span> <span class="n">get_class_name</span><span class="p">(</span><span class="n">trfm</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">binarizer</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">col_names</span><span class="p">)</span>
    <span class="k">elif</span> <span class="s2">&quot;PolynomialFeatures&quot;</span> <span class="o">==</span> <span class="n">get_class_name</span><span class="p">(</span><span class="n">trfm</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">polynomial_features</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">col_names</span><span class="p">)</span>
    <span class="k">elif</span> <span class="s2">&quot;PCA&quot;</span> <span class="o">==</span> <span class="n">get_class_name</span><span class="p">(</span><span class="n">trfm</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">pca</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">col_names</span><span class="p">)</span>
    <span class="k">elif</span> <span class="s2">&quot;LabelBinarizer&quot;</span> <span class="o">==</span> <span class="n">get_class_name</span><span class="p">(</span><span class="n">trfm</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">lbl_binarizer</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">col_names</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
    <span class="k">elif</span> <span class="s2">&quot;OneHotEncoder&quot;</span><span class="o">==</span><span class="n">get_class_name</span><span class="p">(</span><span class="n">trfm</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">one_hot_encoder</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span><span class="n">col_names</span><span class="p">,</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
    <span class="k">elif</span> <span class="s2">&quot;CategoricalImputer&quot;</span> <span class="o">==</span> <span class="n">get_class_name</span><span class="p">(</span><span class="n">trfm</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">cat_imputer</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">col_names</span><span class="p">)</span>
    <span class="k">elif</span> <span class="s2">&quot;Lag&quot;</span> <span class="o">==</span> <span class="n">get_class_name</span><span class="p">(</span><span class="n">trfm</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">lag</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">col_names</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s2">&quot;This PreProcessing Task is not Supported&quot;</span><span class="p">)</span></div>


<div class="viewcode-block" id="get_derived_colnames"><span class="k">def</span> <span class="nf">get_derived_colnames</span><span class="p">(</span><span class="n">trfm_name</span><span class="p">,</span> <span class="n">col_names</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Generates derived column names for a given transformer</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    trfm_name : String</span>
<span class="sd">        Name of the derived field to be assigned after preprocessing</span>
<span class="sd">    col_names : list</span>
<span class="sd">        Contains list of feature/column names.</span>
<span class="sd">        The column names may represent the names of preprocessed attributes.</span>

<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    pml_pp: list</span>
<span class="sd">        Returns a list that contains names of the preprocessed features.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">extra_symbol</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
    <span class="k">if</span> <span class="n">args</span><span class="p">:</span>
        <span class="n">extra_symbol</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
    <span class="n">derived_colnames</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
    <span class="k">for</span> <span class="n">col_name</span> <span class="ow">in</span> <span class="n">col_names</span><span class="p">:</span>
        <span class="n">derived_colnames</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">trfm_name</span> <span class="o">+</span> <span class="s1">&#39;(&#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">col_name</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;)&#39;</span> <span class="o">+</span> <span class="n">extra_symbol</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">derived_colnames</span></div>


<div class="viewcode-block" id="any_in"><span class="k">def</span> <span class="nf">any_in</span><span class="p">(</span><span class="n">seq_a</span><span class="p">,</span> <span class="n">seq_b</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Checks for common elements in two given sequence elements</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    seq_a : list</span>
<span class="sd">        A list of items</span>

<span class="sd">    seq_b : list</span>
<span class="sd">        A list of items</span>

<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    Returns a boolean value if any item of seq_a belongs to seq_b or visa versa</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="nb">any</span><span class="p">(</span><span class="n">elem</span> <span class="ow">in</span> <span class="n">seq_b</span> <span class="k">for</span> <span class="n">elem</span> <span class="ow">in</span> <span class="n">seq_a</span><span class="p">)</span></div>


<span class="c1"># Methods for Preprocessings</span>


<div class="viewcode-block" id="imputer"><span class="k">def</span> <span class="nf">imputer</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">col_names</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Generates pre-processing elements for Scikit-Learn&#39;s Imputer</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    trfm :</span>
<span class="sd">        Contains the Sklearn&#39;s Imputer preprocessing instance</span>
<span class="sd">    col_names : list</span>
<span class="sd">        Contains list of feature/column names.</span>
<span class="sd">        The column names may represent the names of preprocessed attributes.</span>

<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    pp_dict : dictionary</span>
<span class="sd">        Returns a dictionary that contains attributes related to Imputer preprocessing.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">original_col_names</span> <span class="o">=</span> <span class="n">imputer</span><span class="o">.</span><span class="n">col_names</span>
    <span class="n">derived_colnames</span> <span class="o">=</span> <span class="n">col_names</span>
    <span class="n">pp_dict</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
    <span class="n">derived_flds</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>

    <span class="n">model</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;model&#39;</span><span class="p">]</span>

    <span class="n">mining_strategy</span> <span class="o">=</span> <span class="n">trfm</span><span class="o">.</span><span class="n">strategy</span>
    <span class="k">if</span> <span class="s2">&quot;mean&quot;</span> <span class="ow">in</span> <span class="n">mining_strategy</span><span class="p">:</span>
        <span class="n">mining_strategy</span> <span class="o">=</span> <span class="n">MISSING_VALUE_TREATMENT_METHOD</span><span class="o">.</span><span class="n">AS_MEAN</span><span class="o">.</span><span class="n">value</span>
    <span class="k">elif</span> <span class="s2">&quot;median&quot;</span> <span class="ow">in</span> <span class="n">mining_strategy</span><span class="p">:</span>
        <span class="n">mining_strategy</span> <span class="o">=</span> <span class="n">MISSING_VALUE_TREATMENT_METHOD</span><span class="o">.</span><span class="n">AS_MEDIAN</span><span class="o">.</span><span class="n">value</span>
    <span class="k">elif</span> <span class="s2">&quot;most_frequent&quot;</span> <span class="ow">in</span> <span class="n">mining_strategy</span><span class="p">:</span>
        <span class="n">mining_strategy</span> <span class="o">=</span> <span class="n">MISSING_VALUE_TREATMENT_METHOD</span><span class="o">.</span><span class="n">AS_MODE</span><span class="o">.</span><span class="n">value</span>
    <span class="n">mining_replacement_val</span> <span class="o">=</span> <span class="n">trfm</span><span class="o">.</span><span class="n">statistics_</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="n">any_in</span><span class="p">(</span><span class="n">original_col_names</span><span class="p">,</span> <span class="n">col_names</span><span class="p">):</span>
        <span class="n">derived_colnames</span> <span class="o">=</span> <span class="n">get_derived_colnames</span><span class="p">(</span><span class="s1">&#39;imputer&#39;</span><span class="p">,</span> <span class="n">col_names</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">col_name_idx</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">col_names</span><span class="p">)):</span>
            <span class="k">if</span> <span class="p">(</span><span class="n">col_names</span><span class="p">[</span><span class="n">col_name_idx</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">exception_cols</span><span class="p">):</span>
                <span class="n">const_list</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
                <span class="n">apply_inner</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
                <span class="n">apply_inner</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pml</span><span class="o">.</span><span class="n">Apply</span><span class="p">(</span><span class="n">function</span><span class="o">=</span><span class="n">FUNCTION</span><span class="o">.</span><span class="n">IS_MISSING</span><span class="o">.</span><span class="n">value</span><span class="p">,</span> <span class="n">FieldRef</span><span class="o">=</span><span class="p">[</span><span class="n">pml</span><span class="o">.</span><span class="n">FieldRef</span><span class="p">(</span><span class="n">field</span><span class="o">=</span><span class="n">col_names</span><span class="p">[</span><span class="n">col_name_idx</span><span class="p">])]))</span>
                <span class="n">const_obj</span> <span class="o">=</span> <span class="n">pml</span><span class="o">.</span><span class="n">Constant</span><span class="p">(</span>
                    <span class="n">dataType</span><span class="o">=</span><span class="n">DATATYPE</span><span class="o">.</span><span class="n">DOUBLE</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                    <span class="n">valueOf_</span><span class="o">=</span><span class="n">mining_replacement_val</span><span class="p">[</span><span class="n">col_name_idx</span><span class="p">]</span>
                <span class="p">),</span>
                <span class="n">fieldref_obj</span> <span class="o">=</span> <span class="n">pml</span><span class="o">.</span><span class="n">FieldRef</span><span class="p">(</span><span class="n">field</span><span class="o">=</span><span class="n">col_names</span><span class="p">[</span><span class="n">col_name_idx</span><span class="p">])</span>
                <span class="n">fieldref_obj</span><span class="o">.</span><span class="n">original_tagname_</span> <span class="o">=</span> <span class="s2">&quot;FieldRef&quot;</span>
                <span class="n">const_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">const_obj</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
                <span class="n">const_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">fieldref_obj</span><span class="p">)</span>
                <span class="n">apply_outer</span> <span class="o">=</span> <span class="n">pml</span><span class="o">.</span><span class="n">Apply</span><span class="p">(</span>
                    <span class="n">Apply_member</span><span class="o">=</span><span class="n">apply_inner</span><span class="p">,</span>
                    <span class="n">function</span><span class="o">=</span><span class="n">FUNCTION</span><span class="o">.</span><span class="n">IF</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                    <span class="n">Constant</span><span class="o">=</span><span class="n">const_list</span>
                <span class="p">)</span>

                <span class="n">derived_flds</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pml</span><span class="o">.</span><span class="n">DerivedField</span><span class="p">(</span>
                    <span class="n">Apply</span><span class="o">=</span><span class="n">apply_outer</span><span class="p">,</span>
                    <span class="n">name</span><span class="o">=</span><span class="n">derived_colnames</span><span class="p">[</span><span class="n">col_name_idx</span><span class="p">],</span>
                    <span class="n">optype</span><span class="o">=</span><span class="n">OPTYPE</span><span class="o">.</span><span class="n">CONTINUOUS</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                    <span class="n">dataType</span><span class="o">=</span><span class="n">DATATYPE</span><span class="o">.</span><span class="n">DOUBLE</span><span class="o">.</span><span class="n">value</span>
                <span class="p">))</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;mining_strategy&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">mining_strategy</span>
        <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;mining_replacement_val&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">mining_replacement_val</span>
        <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;mining_attributes&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">col_names</span>

    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_fld&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">derived_flds</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_col_names&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">derived_colnames</span>
    <span class="k">return</span> <span class="n">pp_dict</span></div>


<div class="viewcode-block" id="cat_imputer"><span class="k">def</span> <span class="nf">cat_imputer</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">col_names</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Generates pre-processing elements for sklearn-pandas&#39; CategoricalImputer</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    trfm :</span>
<span class="sd">        Contains the Sklearn&#39;s Imputer preprocessing instance</span>
<span class="sd">    col_names : list</span>
<span class="sd">        Contains list of feature/column names.</span>
<span class="sd">        The column names may represent the names of preprocessed attributes.</span>

<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    pp_dict : dictionary</span>
<span class="sd">        Returns a dictionary that contains attributes related to Imputer preprocessing.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">derived_colnames</span> <span class="o">=</span> <span class="n">col_names</span>
    <span class="n">pp_dict</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
    <span class="n">derived_flds</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>

    <span class="n">mining_strategy</span> <span class="o">=</span> <span class="n">MISSING_VALUE_TREATMENT_METHOD</span><span class="o">.</span><span class="n">AS_MODE</span><span class="o">.</span><span class="n">value</span>
    <span class="n">mining_replacement_val</span> <span class="o">=</span> <span class="n">trfm</span><span class="o">.</span><span class="n">fill_</span>

    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;mining_strategy&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">mining_strategy</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;mining_replacement_val&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">mining_replacement_val</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;mining_attributes&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">col_names</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_fld&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">derived_flds</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_col_names&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">derived_colnames</span>

    <span class="k">return</span> <span class="n">pp_dict</span></div>


<div class="viewcode-block" id="pca"><span class="k">def</span> <span class="nf">pca</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">col_names</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Generates pre-processing elements for Scikit-Learn&#39;s PCA</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    trfm :</span>
<span class="sd">        Contains the Sklearn&#39;s PCA preprocessing instance</span>
<span class="sd">    col_names : list</span>
<span class="sd">        Contains list of feature/column names.</span>
<span class="sd">        The column names may represent the names of preprocessed attributes.</span>

<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    pp_dict : dictionary</span>
<span class="sd">        Returns a dictionary that contains attributes related to PCA preprocessing.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">pca</span><span class="o">.</span><span class="n">counter</span> <span class="o">+=</span> <span class="mi">1</span>
    <span class="n">pp_dict</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
    <span class="n">derived_flds</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
    <span class="n">derived_colnames</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
    <span class="n">val</span> <span class="o">=</span> <span class="n">trfm</span><span class="o">.</span><span class="n">mean_</span>
    <span class="n">zero</span> <span class="o">=</span> <span class="mf">0.0</span>
    <span class="k">for</span> <span class="n">preprocess_idx</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">trfm</span><span class="o">.</span><span class="n">n_components_</span><span class="p">):</span>
        <span class="n">add</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">pca_idx</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">trfm</span><span class="o">.</span><span class="n">n_features_</span><span class="p">):</span>
            <span class="n">apply_inner</span> <span class="o">=</span> <span class="n">pml</span><span class="o">.</span><span class="n">Apply</span><span class="p">(</span><span class="n">function</span><span class="o">=</span><span class="n">FUNCTION</span><span class="o">.</span><span class="n">SUBSTRACTTION</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                                    <span class="n">Constant</span><span class="o">=</span><span class="p">[</span><span class="n">pml</span><span class="o">.</span><span class="n">Constant</span><span class="p">(</span><span class="n">dataType</span><span class="o">=</span><span class="n">DATATYPE</span><span class="o">.</span><span class="n">DOUBLE</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                                                           <span class="n">valueOf_</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">{:.16f}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">val</span><span class="p">[</span><span class="n">pca_idx</span><span class="p">]))],</span>
                                    <span class="n">FieldRef</span><span class="o">=</span><span class="p">[</span><span class="n">pml</span><span class="o">.</span><span class="n">FieldRef</span><span class="p">(</span><span class="n">field</span><span class="o">=</span><span class="n">col_names</span><span class="p">[</span><span class="n">pca_idx</span><span class="p">])])</span>
            <span class="n">apply_outer</span> <span class="o">=</span> <span class="n">pml</span><span class="o">.</span><span class="n">Apply</span><span class="p">(</span><span class="n">function</span><span class="o">=</span><span class="n">FUNCTION</span><span class="o">.</span><span class="n">MULTIPLICATION</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                                    <span class="n">Apply_member</span><span class="o">=</span><span class="p">[</span><span class="n">apply_inner</span><span class="p">],</span>
                                    <span class="n">Constant</span><span class="o">=</span><span class="p">[</span><span class="n">pml</span><span class="o">.</span><span class="n">Constant</span><span class="p">(</span><span class="n">dataType</span><span class="o">=</span><span class="n">DATATYPE</span><span class="o">.</span><span class="n">DOUBLE</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                                                           <span class="n">valueOf_</span><span class="o">=</span><span class="n">zero</span> <span class="k">if</span> <span class="n">trfm</span><span class="o">.</span><span class="n">components_</span><span class="p">[</span><span class="n">preprocess_idx</span><span class="p">][</span>
                                                                                <span class="n">pca_idx</span><span class="p">]</span> <span class="o">==</span> <span class="mf">0.0</span> <span class="k">else</span>
                                                           <span class="s2">&quot;</span><span class="si">{:.16f}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">trfm</span><span class="o">.</span><span class="n">components_</span><span class="p">[</span><span class="n">preprocess_idx</span><span class="p">][</span><span class="n">pca_idx</span><span class="p">]))])</span>
            <span class="n">add</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">apply_outer</span><span class="p">)</span>
        <span class="n">app0</span> <span class="o">=</span> <span class="n">pml</span><span class="o">.</span><span class="n">Apply</span><span class="p">(</span><span class="n">function</span><span class="o">=</span><span class="n">FUNCTION</span><span class="o">.</span><span class="n">SUM</span><span class="o">.</span><span class="n">value</span><span class="p">,</span> <span class="n">Apply_member</span><span class="o">=</span><span class="n">add</span><span class="p">)</span>

        <span class="n">derived_flds</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pml</span><span class="o">.</span><span class="n">DerivedField</span><span class="p">(</span><span class="n">Apply</span><span class="o">=</span><span class="n">app0</span><span class="p">,</span>
                                             <span class="n">dataType</span><span class="o">=</span><span class="n">DATATYPE</span><span class="o">.</span><span class="n">DOUBLE</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                                             <span class="n">optype</span><span class="o">=</span><span class="n">OPTYPE</span><span class="o">.</span><span class="n">CONTINUOUS</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                                             <span class="n">name</span><span class="o">=</span><span class="s2">&quot;PCA&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">pca</span><span class="o">.</span><span class="n">counter</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;-&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">preprocess_idx</span><span class="p">)))</span>
        <span class="n">name</span> <span class="o">=</span> <span class="n">derived_flds</span><span class="p">[</span><span class="n">preprocess_idx</span><span class="p">]</span><span class="o">.</span><span class="n">get_name</span><span class="p">()</span>
        <span class="n">derived_colnames</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_fld&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">derived_flds</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_col_names&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">derived_colnames</span>
    <span class="k">return</span> <span class="n">pp_dict</span></div>


<div class="viewcode-block" id="tfidf_vectorizer"><span class="k">def</span> <span class="nf">tfidf_vectorizer</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">col_names</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Generates pre-processing elements for Scikit-Learn&#39;s TfIdfVectorizer</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    trfm :</span>
<span class="sd">        Contains the Sklearn&#39;s TfIdfVectorizer preprocessing instance</span>
<span class="sd">    col_names : list</span>
<span class="sd">        Contains list of feature/column names.</span>
<span class="sd">        The column names may represent the names of preprocessed attributes.</span>

<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    pp_dict : dictionary</span>
<span class="sd">        Returns a dictionary that contains attributes related to TfIdfVectorizer preprocessing.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">pp_dict</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
    <span class="n">features</span> <span class="o">=</span> <span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">feat</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s2">&quot;utf8&quot;</span><span class="p">))[</span><span class="mi">2</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">feat</span> <span class="ow">in</span> <span class="n">trfm</span><span class="o">.</span><span class="n">get_feature_names</span><span class="p">()]</span>
    <span class="n">idfs</span> <span class="o">=</span> <span class="n">trfm</span><span class="o">.</span><span class="n">idf_</span>
    <span class="n">extra_features</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">trfm</span><span class="o">.</span><span class="n">vocabulary_</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>
    <span class="n">derived_flds</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
    <span class="n">derived_colnames</span> <span class="o">=</span> <span class="n">get_derived_colnames</span><span class="p">(</span><span class="s1">&#39;tfidf@[&#39;</span> <span class="o">+</span> <span class="n">col_names</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39;]&#39;</span><span class="p">,</span> <span class="n">features</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">trfm</span><span class="o">.</span><span class="n">lowercase</span><span class="p">:</span>
        <span class="n">derived_flds</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
            <span class="n">pml</span><span class="o">.</span><span class="n">DerivedField</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;lowercase(&#39;</span> <span class="o">+</span> <span class="n">col_names</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39;)&#39;</span><span class="p">,</span>
                            <span class="n">optype</span><span class="o">=</span><span class="n">OPTYPE</span><span class="o">.</span><span class="n">CATEGORICAL</span><span class="o">.</span><span class="n">value</span><span class="p">,</span> <span class="n">dataType</span><span class="o">=</span><span class="n">DATATYPE</span><span class="o">.</span><span class="n">STRING</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                            <span class="n">Apply</span><span class="o">=</span><span class="n">pml</span><span class="o">.</span><span class="n">Apply</span><span class="p">(</span><span class="n">function</span><span class="o">=</span><span class="n">FUNCTION</span><span class="o">.</span><span class="n">LOWERCASE</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                                            <span class="n">FieldRef</span><span class="o">=</span><span class="p">[</span><span class="n">pml</span><span class="o">.</span><span class="n">FieldRef</span><span class="p">(</span><span class="n">field</span><span class="o">=</span><span class="n">col_names</span><span class="p">[</span><span class="mi">0</span><span class="p">])])))</span>
    <span class="k">for</span> <span class="n">feat_idx</span><span class="p">,</span> <span class="n">idf</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">features</span><span class="p">)),</span> <span class="n">idfs</span><span class="p">):</span>
        <span class="n">derived_flds</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pml</span><span class="o">.</span><span class="n">DerivedField</span><span class="p">(</span>
            <span class="n">name</span> <span class="o">=</span> <span class="n">derived_colnames</span><span class="p">[</span><span class="n">feat_idx</span><span class="p">],</span>
            <span class="n">optype</span><span class="o">=</span><span class="n">OPTYPE</span><span class="o">.</span><span class="n">CONTINUOUS</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
            <span class="n">dataType</span><span class="o">=</span><span class="n">DATATYPE</span><span class="o">.</span><span class="n">DOUBLE</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
            <span class="n">Apply</span><span class="o">=</span><span class="n">pml</span><span class="o">.</span><span class="n">Apply</span><span class="p">(</span><span class="n">function</span><span class="o">=</span><span class="n">FUNCTION</span><span class="o">.</span><span class="n">MULTIPLICATION</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                            <span class="n">TextIndex</span><span class="o">=</span><span class="p">[</span><span class="n">pml</span><span class="o">.</span><span class="n">TextIndex</span><span class="p">(</span><span class="n">textField</span><span class="o">=</span><span class="s1">&#39;lowercase(&#39;</span> <span class="o">+</span> <span class="n">col_names</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39;)&#39;</span><span class="p">,</span>
                                                     <span class="n">wordSeparatorCharacterRE</span><span class="o">=</span><span class="s1">&#39;</span><span class="se">\\</span><span class="s1">s+&#39;</span><span class="p">,</span>
                                                     <span class="n">tokenize</span><span class="o">=</span><span class="s1">&#39;true&#39;</span><span class="p">,</span>
                                                     <span class="n">Constant</span><span class="o">=</span><span class="n">pml</span><span class="o">.</span><span class="n">Constant</span><span class="p">(</span><span class="n">valueOf_</span><span class="o">=</span><span class="n">features</span><span class="p">[</span><span class="n">feat_idx</span><span class="p">]),</span>
<span class="n">Extension</span><span class="o">=</span><span class="p">[</span><span class="n">pml</span><span class="o">.</span><span class="n">Extension</span><span class="p">(</span><span class="n">value</span><span class="o">=</span><span class="n">extra_features</span><span class="p">[</span><span class="n">feat_idx</span><span class="p">])])],</span>
                            <span class="n">Constant</span><span class="o">=</span><span class="p">[</span><span class="n">pml</span><span class="o">.</span><span class="n">Constant</span><span class="p">(</span><span class="n">valueOf_</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">{:.16f}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">idf</span><span class="p">))])</span>
                            <span class="p">))</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_fld&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">derived_flds</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_col_names&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">derived_colnames</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;pp_feat_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">col_names</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;pp_feat_class_lbl&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
    <span class="k">return</span> <span class="n">pp_dict</span></div>


<div class="viewcode-block" id="count_vectorizer"><span class="k">def</span> <span class="nf">count_vectorizer</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">col_names</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Generates pre-processing elements for Scikit-Learn&#39;s CountVectorizer</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    trfm :</span>
<span class="sd">        Contains the Sklearn&#39;s CountVectorizer preprocessing instance.</span>
<span class="sd">    col_names : list</span>
<span class="sd">        Contains list of feature/column names.</span>
<span class="sd">        The column names may represent the names of preprocessed attributes.</span>

<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    pp_dict : dictionary</span>
<span class="sd">        Returns a dictionary that contains attributes related to CountVectorizer preprocessing.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">pp_dict</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
    <span class="n">features</span> <span class="o">=</span> <span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">feat</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s2">&quot;utf8&quot;</span><span class="p">))[</span><span class="mi">2</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">feat</span> <span class="ow">in</span> <span class="n">trfm</span><span class="o">.</span><span class="n">get_feature_names</span><span class="p">()]</span>
    <span class="n">extra_features</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">trfm</span><span class="o">.</span><span class="n">vocabulary_</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>
    <span class="n">derived_flds</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
    <span class="n">derived_colnames</span> <span class="o">=</span> <span class="n">get_derived_colnames</span><span class="p">(</span><span class="s1">&#39;count_vec@[&#39;</span> <span class="o">+</span> <span class="n">col_names</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39;]&#39;</span><span class="p">,</span> <span class="n">features</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">trfm</span><span class="o">.</span><span class="n">lowercase</span><span class="p">:</span>
        <span class="n">derived_flds</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pml</span><span class="o">.</span><span class="n">DerivedField</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;lowercase(&#39;</span> <span class="o">+</span> <span class="n">col_names</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39;)&#39;</span><span class="p">,</span>
                                            <span class="n">optype</span><span class="o">=</span><span class="n">OPTYPE</span><span class="o">.</span><span class="n">CATEGORICAL</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                                            <span class="n">dataType</span><span class="o">=</span><span class="n">DATATYPE</span><span class="o">.</span><span class="n">STRING</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                                            <span class="n">Apply</span><span class="o">=</span><span class="n">pml</span><span class="o">.</span><span class="n">Apply</span><span class="p">(</span><span class="n">function</span><span class="o">=</span><span class="n">FUNCTION</span><span class="o">.</span><span class="n">LOWERCASE</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                                                            <span class="n">FieldRef</span><span class="o">=</span><span class="p">[</span><span class="n">pml</span><span class="o">.</span><span class="n">FieldRef</span><span class="p">(</span><span class="n">field</span><span class="o">=</span><span class="n">col_names</span><span class="p">[</span><span class="mi">0</span><span class="p">])])))</span>
    <span class="k">for</span> <span class="n">imp_features</span><span class="p">,</span> <span class="n">index</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">features</span><span class="p">,</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">features</span><span class="p">))):</span>
        <span class="n">df_name</span> <span class="o">=</span> <span class="n">derived_colnames</span><span class="p">[</span><span class="n">index</span><span class="p">]</span>
        <span class="n">derived_flds</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pml</span><span class="o">.</span><span class="n">DerivedField</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">df_name</span><span class="p">,</span>
                                            <span class="n">optype</span><span class="o">=</span><span class="n">OPTYPE</span><span class="o">.</span><span class="n">CONTINUOUS</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                                            <span class="n">dataType</span><span class="o">=</span><span class="n">DATATYPE</span><span class="o">.</span><span class="n">DOUBLE</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                                            <span class="n">TextIndex</span><span class="o">=</span><span class="n">pml</span><span class="o">.</span><span class="n">TextIndex</span><span class="p">(</span><span class="n">textField</span><span class="o">=</span><span class="s1">&#39;lowercase(&#39;</span> <span class="o">+</span> <span class="n">col_names</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39;)&#39;</span> <span class="k">if</span> <span class="n">trfm</span><span class="o">.</span><span class="n">lowercase</span> \
                                                <span class="k">else</span> <span class="n">col_names</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
                                                                    <span class="n">wordSeparatorCharacterRE</span><span class="o">=</span><span class="s1">&#39;</span><span class="se">\\</span><span class="s1">s+&#39;</span><span class="p">,</span>
                                                                    <span class="n">tokenize</span><span class="o">=</span><span class="s1">&#39;true&#39;</span><span class="p">,</span>
                                                                    <span class="n">Constant</span><span class="o">=</span><span class="n">pml</span><span class="o">.</span><span class="n">Constant</span><span class="p">(</span><span class="n">dataType</span><span class="o">=</span><span class="n">DATATYPE</span><span class="o">.</span><span class="n">STRING</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                                                                                        <span class="n">valueOf_</span><span class="o">=</span><span class="n">imp_features</span><span class="p">),</span>
                                                                    <span class="n">Extension</span><span class="o">=</span><span class="p">[</span><span class="n">pml</span><span class="o">.</span><span class="n">Extension</span><span class="p">(</span><span class="n">value</span><span class="o">=</span><span class="n">extra_features</span><span class="p">[</span><span class="n">index</span><span class="p">])]</span>
                                                                    <span class="p">)))</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_fld&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">derived_flds</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_col_names&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">derived_colnames</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;pp_feat_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">col_names</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;pp_feat_class_lbl&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
    <span class="k">return</span> <span class="n">pp_dict</span></div>


<div class="viewcode-block" id="lag"><span class="k">def</span> <span class="nf">lag</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">col_names</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Generates pre-processing elements for Nyoka&#39;s Lag</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    trfm :</span>
<span class="sd">        Contains the Nyoka&#39;s Lag instance.</span>
<span class="sd">    col_names : list</span>
<span class="sd">        Contains list of feature/column names.</span>
<span class="sd">        The column names may represent the names of preprocessed attributes.</span>

<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    pp_dict : dictionary</span>
<span class="sd">        Returns a dictionary that contains attributes related to Lag preprocessing.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">derived_flds</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
    <span class="n">pp_dict</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
    <span class="n">derived_colnames</span> <span class="o">=</span> <span class="n">get_derived_colnames</span><span class="p">(</span><span class="n">trfm</span><span class="o">.</span><span class="n">aggregation</span><span class="p">,</span> <span class="n">col_names</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">idx</span><span class="p">,</span> <span class="n">name</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">col_names</span><span class="p">):</span>
        <span class="n">lag</span> <span class="o">=</span> <span class="n">pml</span><span class="o">.</span><span class="n">Lag</span><span class="p">(</span><span class="n">field</span><span class="o">=</span><span class="n">name</span><span class="p">,</span> <span class="n">n</span><span class="o">=</span><span class="n">trfm</span><span class="o">.</span><span class="n">value</span><span class="p">,</span> <span class="n">aggregate</span><span class="o">=</span><span class="n">trfm</span><span class="o">.</span><span class="n">aggregation</span><span class="p">)</span>
        <span class="n">derived_fld</span> <span class="o">=</span> <span class="n">pml</span><span class="o">.</span><span class="n">DerivedField</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">derived_colnames</span><span class="p">[</span><span class="n">idx</span><span class="p">],</span> <span class="n">Lag</span><span class="o">=</span><span class="n">lag</span><span class="p">,</span> <span class="n">optype</span><span class="o">=</span><span class="n">OPTYPE</span><span class="o">.</span><span class="n">CONTINUOUS</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>\
             <span class="n">dataType</span><span class="o">=</span><span class="n">DATATYPE</span><span class="o">.</span><span class="n">DOUBLE</span><span class="o">.</span><span class="n">value</span><span class="p">)</span>
        <span class="n">derived_flds</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">derived_fld</span><span class="p">)</span>
    
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_fld&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">derived_flds</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_col_names&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">derived_colnames</span>
    <span class="k">return</span> <span class="n">pp_dict</span>   </div>



<div class="viewcode-block" id="std_scaler"><span class="k">def</span> <span class="nf">std_scaler</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">col_names</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Generates pre-processing elements for Scikit-Learn&#39;s StandardScaler</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    trfm :</span>
<span class="sd">        Contains the Sklearn&#39;s Standard Scaler preprocessing instance</span>
<span class="sd">    col_names : list</span>
<span class="sd">        Contains list of feature/column names.</span>
<span class="sd">        The column names may represent the names of preprocessed attributes.</span>

<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    pp_dict : dictionary</span>
<span class="sd">        Returns a dictionary that contains attributes related to Standard Scaler preprocessing.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">derived_flds</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
    <span class="n">pp_dict</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>

    <span class="n">derived_colnames</span> <span class="o">=</span> <span class="n">get_derived_colnames</span><span class="p">(</span><span class="s1">&#39;standardScaler&#39;</span><span class="p">,</span> <span class="n">col_names</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">col_name_idx</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">col_names</span><span class="p">)):</span>
        <span class="n">apply_inner</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
        <span class="n">apply_inner</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pml</span><span class="o">.</span><span class="n">Apply</span><span class="p">(</span>
            <span class="n">function</span><span class="o">=</span><span class="n">FUNCTION</span><span class="o">.</span><span class="n">SUBSTRACTTION</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
            <span class="n">Constant</span><span class="o">=</span><span class="p">[</span><span class="n">pml</span><span class="o">.</span><span class="n">Constant</span><span class="p">(</span>
                <span class="n">dataType</span><span class="o">=</span><span class="n">DATATYPE</span><span class="o">.</span><span class="n">DOUBLE</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>  
                <span class="n">valueOf_</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">{:.16f}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">trfm</span><span class="o">.</span><span class="n">mean_</span><span class="p">[</span><span class="n">col_name_idx</span><span class="p">])</span>
            <span class="p">)],</span>
            <span class="n">FieldRef</span><span class="o">=</span><span class="p">[</span><span class="n">pml</span><span class="o">.</span><span class="n">FieldRef</span><span class="p">(</span><span class="n">field</span><span class="o">=</span><span class="n">col_names</span><span class="p">[</span><span class="n">col_name_idx</span><span class="p">])]</span>
        <span class="p">))</span>
        <span class="n">apply_outer</span> <span class="o">=</span> <span class="n">pml</span><span class="o">.</span><span class="n">Apply</span><span class="p">(</span>
            <span class="n">Apply_member</span><span class="o">=</span><span class="n">apply_inner</span><span class="p">,</span>
            <span class="n">function</span><span class="o">=</span><span class="n">FUNCTION</span><span class="o">.</span><span class="n">DIVISION</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
            <span class="n">Constant</span><span class="o">=</span><span class="p">[</span><span class="n">pml</span><span class="o">.</span><span class="n">Constant</span><span class="p">(</span>
                <span class="n">dataType</span><span class="o">=</span><span class="n">DATATYPE</span><span class="o">.</span><span class="n">DOUBLE</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                <span class="n">valueOf_</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">{:.16f}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">trfm</span><span class="o">.</span><span class="n">scale_</span><span class="p">[</span><span class="n">col_name_idx</span><span class="p">])</span>
            <span class="p">)]</span>
        <span class="p">)</span>
        <span class="n">derived_flds</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pml</span><span class="o">.</span><span class="n">DerivedField</span><span class="p">(</span>
            <span class="n">Apply</span><span class="o">=</span><span class="n">apply_outer</span><span class="p">,</span>
            <span class="n">name</span><span class="o">=</span><span class="n">derived_colnames</span><span class="p">[</span><span class="n">col_name_idx</span><span class="p">],</span>
            <span class="n">optype</span><span class="o">=</span><span class="n">OPTYPE</span><span class="o">.</span><span class="n">CONTINUOUS</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
            <span class="n">dataType</span><span class="o">=</span><span class="n">DATATYPE</span><span class="o">.</span><span class="n">DOUBLE</span><span class="o">.</span><span class="n">value</span>
        <span class="p">))</span>


    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_fld&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">derived_flds</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_col_names&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">derived_colnames</span>
    <span class="k">return</span> <span class="n">pp_dict</span></div>


<div class="viewcode-block" id="min_max_scaler"><span class="k">def</span> <span class="nf">min_max_scaler</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">col_names</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Generates pre-processing elements for Scikit-Learn&#39;s MinMaxScaler</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    trfm :</span>
<span class="sd">        Contains the Sklearn&#39;s MinMaxScaler preprocessing instance</span>
<span class="sd">    col_names : list</span>
<span class="sd">        Contains list of feature/column names.</span>
<span class="sd">        The column names may represent the names of preprocessed attributes.</span>

<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    pp_dict : dictionary</span>
<span class="sd">        Returns a dictionary that contains attributes related to MinMaxScaler preprocessing.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">pp_dict</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
    <span class="n">derived_flds</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
    <span class="n">derived_colnames</span> <span class="o">=</span> <span class="n">get_derived_colnames</span><span class="p">(</span><span class="s2">&quot;minMaxScaler&quot;</span><span class="p">,</span> <span class="n">col_names</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">col_name_idx</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">col_names</span><span class="p">)):</span>
        <span class="k">if</span><span class="p">(</span><span class="n">col_names</span><span class="p">[</span><span class="n">col_name_idx</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">exception_cols</span><span class="p">):</span>
            <span class="n">apply_inner</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
            <span class="n">apply_inner</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pml</span><span class="o">.</span><span class="n">Apply</span><span class="p">(</span>
                <span class="n">function</span><span class="o">=</span><span class="n">FUNCTION</span><span class="o">.</span><span class="n">MULTIPLICATION</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                <span class="n">Constant</span><span class="o">=</span><span class="p">[</span><span class="n">pml</span><span class="o">.</span><span class="n">Constant</span><span class="p">(</span>
                    <span class="n">dataType</span><span class="o">=</span><span class="n">DATATYPE</span><span class="o">.</span><span class="n">DOUBLE</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                    <span class="n">valueOf_</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">{:.16f}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">trfm</span><span class="o">.</span><span class="n">scale_</span><span class="p">[</span><span class="n">col_name_idx</span><span class="p">])</span>
                <span class="p">)],</span>
                <span class="n">FieldRef</span><span class="o">=</span><span class="p">[</span><span class="n">pml</span><span class="o">.</span><span class="n">FieldRef</span><span class="p">(</span><span class="n">field</span><span class="o">=</span><span class="n">col_names</span><span class="p">[</span><span class="n">col_name_idx</span><span class="p">])]</span>
            <span class="p">))</span>
            <span class="n">apply_outer</span> <span class="o">=</span> <span class="n">pml</span><span class="o">.</span><span class="n">Apply</span><span class="p">(</span>
                <span class="n">Apply_member</span><span class="o">=</span><span class="n">apply_inner</span><span class="p">,</span>
                <span class="n">function</span><span class="o">=</span><span class="n">FUNCTION</span><span class="o">.</span><span class="n">ADDITION</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                <span class="n">Constant</span><span class="o">=</span><span class="p">[</span><span class="n">pml</span><span class="o">.</span><span class="n">Constant</span><span class="p">(</span>
                    <span class="n">dataType</span><span class="o">=</span><span class="n">DATATYPE</span><span class="o">.</span><span class="n">DOUBLE</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                    <span class="n">valueOf_</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">{:.16f}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">trfm</span><span class="o">.</span><span class="n">min_</span><span class="p">[</span><span class="n">col_name_idx</span><span class="p">])</span>
                <span class="p">)]</span>
            <span class="p">)</span>
            <span class="n">derived_flds</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pml</span><span class="o">.</span><span class="n">DerivedField</span><span class="p">(</span>
                <span class="n">Apply</span><span class="o">=</span><span class="n">apply_outer</span><span class="p">,</span>
                <span class="n">name</span><span class="o">=</span><span class="n">derived_colnames</span><span class="p">[</span><span class="n">col_name_idx</span><span class="p">],</span>
                <span class="n">optype</span><span class="o">=</span><span class="n">OPTYPE</span><span class="o">.</span><span class="n">CONTINUOUS</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                <span class="n">dataType</span><span class="o">=</span><span class="n">DATATYPE</span><span class="o">.</span><span class="n">DOUBLE</span><span class="o">.</span><span class="n">value</span>
            <span class="p">))</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_fld&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">derived_flds</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_col_names&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">derived_colnames</span>
    <span class="k">return</span> <span class="n">pp_dict</span></div>


<div class="viewcode-block" id="rbst_scaler"><span class="k">def</span> <span class="nf">rbst_scaler</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">col_names</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Generates pre-processing elements for Scikit-Learn&#39;s RobustScaler</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    trfm :</span>
<span class="sd">        Contains the Sklearn&#39;s RobustScaler preprocessing instance</span>
<span class="sd">    col_names : list</span>
<span class="sd">        Contains list of feature/column names.</span>
<span class="sd">        The column names may represent the names of preprocessed attributes.</span>

<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    pp_dict : dictionary</span>
<span class="sd">        Returns a dictionary that contains attributes related to RobustScaler preprocessing.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">pp_dict</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
    <span class="n">derived_flds</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
    <span class="n">derived_colnames</span> <span class="o">=</span> <span class="n">get_derived_colnames</span><span class="p">(</span><span class="s1">&#39;robustScaler&#39;</span><span class="p">,</span> <span class="n">col_names</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">col_name_idx</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">col_names</span><span class="p">)):</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">col_names</span><span class="p">[</span><span class="n">col_name_idx</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">exception_cols</span><span class="p">):</span>
            <span class="n">apply_inner</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
            <span class="n">apply_inner</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pml</span><span class="o">.</span><span class="n">Apply</span><span class="p">(</span>
                <span class="n">function</span><span class="o">=</span><span class="n">FUNCTION</span><span class="o">.</span><span class="n">SUBSTRACTTION</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                <span class="n">Constant</span><span class="o">=</span><span class="p">[</span><span class="n">pml</span><span class="o">.</span><span class="n">Constant</span><span class="p">(</span>
                    <span class="n">dataType</span><span class="o">=</span><span class="n">DATATYPE</span><span class="o">.</span><span class="n">DOUBLE</span><span class="o">.</span><span class="n">value</span><span class="p">,</span> 
                    <span class="n">valueOf_</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">{:.16f}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">trfm</span><span class="o">.</span><span class="n">center_</span><span class="p">[</span><span class="n">col_name_idx</span><span class="p">])</span>
                <span class="p">)],</span>
                <span class="n">FieldRef</span><span class="o">=</span><span class="p">[</span><span class="n">pml</span><span class="o">.</span><span class="n">FieldRef</span><span class="p">(</span><span class="n">field</span><span class="o">=</span><span class="n">col_names</span><span class="p">[</span><span class="n">col_name_idx</span><span class="p">])]</span>
            <span class="p">))</span>
            <span class="n">apply_outer</span> <span class="o">=</span> <span class="n">pml</span><span class="o">.</span><span class="n">Apply</span><span class="p">(</span>
                <span class="n">Apply_member</span><span class="o">=</span><span class="n">apply_inner</span><span class="p">,</span>
                <span class="n">function</span><span class="o">=</span><span class="n">FUNCTION</span><span class="o">.</span><span class="n">DIVISION</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                <span class="n">Constant</span><span class="o">=</span><span class="p">[</span><span class="n">pml</span><span class="o">.</span><span class="n">Constant</span><span class="p">(</span>
                    <span class="n">dataType</span><span class="o">=</span><span class="n">DATATYPE</span><span class="o">.</span><span class="n">DOUBLE</span><span class="o">.</span><span class="n">value</span><span class="p">,</span> 
                    <span class="n">valueOf_</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">{:.16f}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">trfm</span><span class="o">.</span><span class="n">scale_</span><span class="p">[</span><span class="n">col_name_idx</span><span class="p">])</span>
                <span class="p">)]</span>
            <span class="p">)</span>
            <span class="n">derived_flds</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pml</span><span class="o">.</span><span class="n">DerivedField</span><span class="p">(</span>
                <span class="n">Apply</span><span class="o">=</span><span class="n">apply_outer</span><span class="p">,</span>
                <span class="n">name</span><span class="o">=</span><span class="n">derived_colnames</span><span class="p">[</span><span class="n">col_name_idx</span><span class="p">],</span>
                <span class="n">optype</span><span class="o">=</span><span class="n">OPTYPE</span><span class="o">.</span><span class="n">CONTINUOUS</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                <span class="n">dataType</span><span class="o">=</span><span class="n">DATATYPE</span><span class="o">.</span><span class="n">DOUBLE</span><span class="o">.</span><span class="n">value</span>
            <span class="p">))</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_fld&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">derived_flds</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_col_names&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">derived_colnames</span>
    <span class="k">return</span> <span class="n">pp_dict</span></div>


<div class="viewcode-block" id="max_abs_scaler"><span class="k">def</span> <span class="nf">max_abs_scaler</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">col_names</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Generates pre-processing elements for Scikit-Learn&#39;s MaxAbsScaler</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    trfm :</span>
<span class="sd">        Contains the Sklearn&#39;s MaxabsScaler preprocessing instance</span>
<span class="sd">    col_names : list</span>
<span class="sd">        Contains list of feature/column names.</span>
<span class="sd">        The column names may represent the names of preprocessed attributes.</span>

<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    pp_dict : dictionary</span>
<span class="sd">        Returns a dictionary that contains attributes related to MaxabsScaler preprocessing.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">pp_dict</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
    <span class="n">derived_flds</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
    <span class="n">derived_colnames</span> <span class="o">=</span> <span class="n">get_derived_colnames</span><span class="p">(</span><span class="s1">&#39;maxAbsScaler&#39;</span><span class="p">,</span> <span class="n">col_names</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">col_name_idx</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">col_names</span><span class="p">)):</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">col_names</span><span class="p">[</span><span class="n">col_name_idx</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">exception_cols</span><span class="p">):</span>
            <span class="n">apply_outer</span> <span class="o">=</span> <span class="n">pml</span><span class="o">.</span><span class="n">Apply</span><span class="p">(</span>
                <span class="n">function</span><span class="o">=</span><span class="n">FUNCTION</span><span class="o">.</span><span class="n">DIVISION</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                <span class="n">Constant</span><span class="o">=</span><span class="p">[</span><span class="n">pml</span><span class="o">.</span><span class="n">Constant</span><span class="p">(</span>
                    <span class="n">dataType</span><span class="o">=</span><span class="n">DATATYPE</span><span class="o">.</span><span class="n">DOUBLE</span><span class="o">.</span><span class="n">value</span><span class="p">,</span> 
                    <span class="n">valueOf_</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">{:.16f}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">trfm</span><span class="o">.</span><span class="n">max_abs_</span><span class="p">[</span><span class="n">col_name_idx</span><span class="p">])</span>
                <span class="p">)],</span>
                <span class="n">FieldRef</span><span class="o">=</span><span class="p">[</span><span class="n">pml</span><span class="o">.</span><span class="n">FieldRef</span><span class="p">(</span><span class="n">field</span><span class="o">=</span><span class="n">col_names</span><span class="p">[</span><span class="n">col_name_idx</span><span class="p">])]</span>
            <span class="p">)</span>

            <span class="n">derived_flds</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pml</span><span class="o">.</span><span class="n">DerivedField</span><span class="p">(</span>
                <span class="n">Apply</span><span class="o">=</span><span class="n">apply_outer</span><span class="p">,</span>
                <span class="n">name</span><span class="o">=</span><span class="n">derived_colnames</span><span class="p">[</span><span class="n">col_name_idx</span><span class="p">],</span>
                <span class="n">optype</span><span class="o">=</span><span class="n">OPTYPE</span><span class="o">.</span><span class="n">CONTINUOUS</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                <span class="n">dataType</span><span class="o">=</span><span class="n">DATATYPE</span><span class="o">.</span><span class="n">DOUBLE</span><span class="o">.</span><span class="n">value</span>
            <span class="p">))</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_fld&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">derived_flds</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_col_names&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">derived_colnames</span>
    <span class="k">return</span> <span class="n">pp_dict</span></div>


<div class="viewcode-block" id="lbl_encoder"><span class="k">def</span> <span class="nf">lbl_encoder</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">col_names</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Generates pre-processing elements for Scikit-Learn&#39;s LabelEncoder</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    trfm :</span>
<span class="sd">        Contains the Sklearn&#39;s LabelEncoder preprocessing instance</span>
<span class="sd">    col_names : list</span>
<span class="sd">        Contains list of feature/column names.</span>
<span class="sd">        The column names may represent the names of preprocessed attributes.</span>

<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    pp_dict : dictionary</span>
<span class="sd">        Returns a dictionary that contains attributes related to LabelEncoder preprocessing.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">pp_dict</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
    <span class="n">derived_flds</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
    <span class="n">field_column_pair</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
    <span class="n">rows</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">categoric_lbls</span> <span class="o">=</span> <span class="n">trfm</span><span class="o">.</span><span class="n">classes_</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
    <span class="n">categoric_lbls_num</span> <span class="o">=</span> <span class="n">trfm</span><span class="o">.</span><span class="n">transform</span><span class="p">(</span><span class="n">trfm</span><span class="o">.</span><span class="n">classes_</span><span class="o">.</span><span class="n">tolist</span><span class="p">())</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
    <span class="n">derived_colnames</span> <span class="o">=</span> <span class="n">get_derived_colnames</span><span class="p">(</span><span class="s1">&#39;labelEncoder&#39;</span><span class="p">,</span> <span class="n">col_names</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">row_idx</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">categoric_lbls_num</span><span class="p">)):</span>
        <span class="n">row_main</span> <span class="o">=</span> <span class="n">pml</span><span class="o">.</span><span class="n">row</span><span class="p">()</span>
        <span class="n">row_main</span><span class="o">.</span><span class="n">elementobjs_</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;input&#39;</span><span class="p">,</span> <span class="s1">&#39;output&#39;</span><span class="p">]</span>
        <span class="n">row_main</span><span class="o">.</span><span class="n">input</span> <span class="o">=</span> <span class="n">categoric_lbls</span><span class="p">[</span><span class="n">row_idx</span><span class="p">]</span>
        <span class="n">row_main</span><span class="o">.</span><span class="n">output</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">categoric_lbls_num</span><span class="p">[</span><span class="n">row_idx</span><span class="p">])</span>
        <span class="n">rows</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">row_main</span><span class="p">)</span>
    <span class="n">field_column_pair</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pml</span><span class="o">.</span><span class="n">FieldColumnPair</span><span class="p">(</span><span class="n">field</span><span class="o">=</span><span class="nb">str</span><span class="p">(</span><span class="n">col_names</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span> <span class="n">column</span><span class="o">=</span><span class="s2">&quot;input&quot;</span><span class="p">))</span>
    <span class="n">inline_table</span> <span class="o">=</span> <span class="n">pml</span><span class="o">.</span><span class="n">InlineTable</span><span class="p">(</span><span class="n">row</span><span class="o">=</span><span class="n">rows</span><span class="p">)</span>
    <span class="n">map_values</span> <span class="o">=</span> <span class="n">pml</span><span class="o">.</span><span class="n">MapValues</span><span class="p">(</span><span class="n">outputColumn</span><span class="o">=</span><span class="s2">&quot;output&quot;</span><span class="p">,</span> <span class="n">FieldColumnPair</span><span class="o">=</span><span class="n">field_column_pair</span><span class="p">,</span> <span class="n">InlineTable</span><span class="o">=</span><span class="n">inline_table</span><span class="p">)</span>
    <span class="n">derived_flds</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
        <span class="n">pml</span><span class="o">.</span><span class="n">DerivedField</span><span class="p">(</span><span class="n">MapValues</span><span class="o">=</span><span class="n">map_values</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">derived_colnames</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">optype</span><span class="o">=</span><span class="n">OPTYPE</span><span class="o">.</span><span class="n">CONTINUOUS</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>\
             <span class="n">dataType</span><span class="o">=</span><span class="n">DATATYPE</span><span class="o">.</span><span class="n">DOUBLE</span><span class="o">.</span><span class="n">value</span><span class="p">))</span>

    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_fld&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">derived_flds</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_col_names&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">derived_colnames</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;pp_feat_class_lbl&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">categoric_lbls</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;pp_feat_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">col_names</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

    <span class="k">return</span> <span class="n">pp_dict</span></div>


<div class="viewcode-block" id="binarizer"><span class="k">def</span> <span class="nf">binarizer</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">col_names</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Generates pre-processing elements for Scikit-Learn&#39;s Binarizer</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    trfm :</span>
<span class="sd">        Contains the Sklearn&#39;s Binarizer preprocessing instance.</span>
<span class="sd">    col_names : list</span>
<span class="sd">        Contains list of feature/column names.</span>
<span class="sd">        The column names may represent the names of preprocessed attributes.</span>

<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    pp_dict : dictionary</span>
<span class="sd">        Returns a dictionary that contains attributes related to Binarizer preprocessing.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">pp_dict</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
    <span class="n">derived_flds</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
    <span class="n">derived_colnames</span> <span class="o">=</span> <span class="n">get_derived_colnames</span><span class="p">(</span><span class="s2">&quot;binarizer&quot;</span><span class="p">,</span> <span class="n">col_names</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">col_name_idx</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">col_names</span><span class="p">)):</span>
        <span class="n">apply_outer</span> <span class="o">=</span> <span class="n">pml</span><span class="o">.</span><span class="n">Apply</span><span class="p">(</span>
            <span class="n">function</span><span class="o">=</span><span class="n">FUNCTION</span><span class="o">.</span><span class="n">THRESHOLD</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
            <span class="n">Constant</span><span class="o">=</span><span class="p">[</span><span class="n">pml</span><span class="o">.</span><span class="n">Constant</span><span class="p">(</span>
                <span class="n">dataType</span><span class="o">=</span><span class="n">DATATYPE</span><span class="o">.</span><span class="n">DOUBLE</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                <span class="n">valueOf_</span><span class="o">=</span><span class="n">trfm</span><span class="o">.</span><span class="n">threshold</span>
            <span class="p">)],</span>
            <span class="n">FieldRef</span><span class="o">=</span><span class="p">[</span><span class="n">pml</span><span class="o">.</span><span class="n">FieldRef</span><span class="p">(</span><span class="n">field</span><span class="o">=</span><span class="n">col_names</span><span class="p">[</span><span class="n">col_name_idx</span><span class="p">])])</span>

        <span class="n">derived_flds</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pml</span><span class="o">.</span><span class="n">DerivedField</span><span class="p">(</span>
            <span class="n">Apply</span><span class="o">=</span><span class="n">apply_outer</span><span class="p">,</span>
            <span class="n">name</span><span class="o">=</span><span class="n">derived_colnames</span><span class="p">[</span><span class="n">col_name_idx</span><span class="p">],</span>
            <span class="n">optype</span><span class="o">=</span><span class="n">OPTYPE</span><span class="o">.</span><span class="n">CONTINUOUS</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
            <span class="n">dataType</span><span class="o">=</span><span class="n">DATATYPE</span><span class="o">.</span><span class="n">DOUBLE</span><span class="o">.</span><span class="n">value</span>
        <span class="p">))</span>

    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_fld&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">derived_flds</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_col_names&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">derived_colnames</span>
    <span class="k">return</span> <span class="n">pp_dict</span></div>


<div class="viewcode-block" id="polynomial_features"><span class="k">def</span> <span class="nf">polynomial_features</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">col_names</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Generates pre-processing elements for Scikit-Learn&#39;s PolynomialFeatures</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    trfm :</span>
<span class="sd">        Contains the Sklearn&#39;s PolynomialFeatures preprocessing instance.</span>
<span class="sd">    col_names : list</span>
<span class="sd">        Contains list of feature/column names.</span>
<span class="sd">        The column names may represent the names of preprocessed attributes.</span>

<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    pp_dict : dictionary</span>
<span class="sd">        Returns a dictionary that contains attributes related to PolynomialFeatures preprocessing.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">polynomial_features</span><span class="o">.</span><span class="n">poly_ctr</span> <span class="o">+=</span> <span class="mi">1</span>
    <span class="n">pp_dict</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
    <span class="n">derived_flds</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">derived_colnames</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="k">for</span> <span class="n">polyfeat_idx</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">trfm</span><span class="o">.</span><span class="n">powers_</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]):</span>
        <span class="n">apply_inner_container</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">col_name_idx</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">col_names</span><span class="p">)):</span>
            <span class="n">val</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">trfm</span><span class="o">.</span><span class="n">powers_</span><span class="p">[</span><span class="n">polyfeat_idx</span><span class="p">][</span><span class="n">col_name_idx</span><span class="p">])</span>
            <span class="n">apply_inner</span> <span class="o">=</span> <span class="n">pml</span><span class="o">.</span><span class="n">Apply</span><span class="p">(</span>
                <span class="n">function</span><span class="o">=</span><span class="n">FUNCTION</span><span class="o">.</span><span class="n">POWER</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                <span class="n">Constant</span><span class="o">=</span><span class="p">[</span><span class="n">pml</span><span class="o">.</span><span class="n">Constant</span><span class="p">(</span>
                    <span class="n">dataType</span><span class="o">=</span><span class="n">DATATYPE</span><span class="o">.</span><span class="n">INTEGER</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                    <span class="n">valueOf_</span><span class="o">=</span><span class="n">val</span>
                <span class="p">)],</span>
                <span class="n">FieldRef</span><span class="o">=</span><span class="p">[</span><span class="n">pml</span><span class="o">.</span><span class="n">FieldRef</span><span class="p">(</span><span class="n">field</span><span class="o">=</span><span class="n">col_names</span><span class="p">[</span><span class="n">col_name_idx</span><span class="p">])])</span>
            <span class="n">apply_inner_container</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">apply_inner</span><span class="p">)</span>
        <span class="n">apply_outer</span> <span class="o">=</span> <span class="n">pml</span><span class="o">.</span><span class="n">Apply</span><span class="p">(</span><span class="n">function</span><span class="o">=</span><span class="n">FUNCTION</span><span class="o">.</span><span class="n">PRODUCT</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                                <span class="n">Apply_member</span><span class="o">=</span><span class="n">apply_inner_container</span>
                                <span class="p">)</span>
        <span class="n">derived_flds</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pml</span><span class="o">.</span><span class="n">DerivedField</span><span class="p">(</span>
            <span class="n">Apply</span><span class="o">=</span><span class="n">apply_outer</span><span class="p">,</span>
            <span class="n">dataType</span><span class="o">=</span><span class="n">DATATYPE</span><span class="o">.</span><span class="n">DOUBLE</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
            <span class="n">optype</span><span class="o">=</span><span class="n">OPTYPE</span><span class="o">.</span><span class="n">CONTINUOUS</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
            <span class="n">name</span><span class="o">=</span><span class="s2">&quot;poly&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">polynomial_features</span><span class="o">.</span><span class="n">poly_ctr</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;-&#39;</span> <span class="o">+</span> <span class="s2">&quot;x&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">polyfeat_idx</span><span class="p">)</span>
        <span class="p">))</span>
        <span class="n">name</span> <span class="o">=</span> <span class="n">derived_flds</span><span class="p">[</span><span class="n">polyfeat_idx</span><span class="p">]</span><span class="o">.</span><span class="n">get_name</span><span class="p">()</span>
        <span class="n">derived_colnames</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_fld&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">derived_flds</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_col_names&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">derived_colnames</span>
    <span class="k">return</span> <span class="n">pp_dict</span></div>


<div class="viewcode-block" id="lbl_binarizer"><span class="k">def</span> <span class="nf">lbl_binarizer</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">col_names</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Generates pre-processing elements for Scikit-Learn&#39;s LabelBinarizer</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    trfm :</span>
<span class="sd">        Contains the Sklearn&#39;s Label Binarizer preprocessing instance.</span>
<span class="sd">    col_names : list</span>
<span class="sd">        Contains list of feature/column names.</span>
<span class="sd">        The column names may represent the names of preprocessed attributes.</span>

<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    pp_dict : dictionary</span>
<span class="sd">        Returns a dictionary that contains attributes related to Label Binarizer preprocessing.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">derived_flds</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
    <span class="n">derived_colnames</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
    <span class="n">pp_dict</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
    <span class="n">categoric_lbls</span> <span class="o">=</span> <span class="n">trfm</span><span class="o">.</span><span class="n">classes_</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
    <span class="k">for</span> <span class="n">col_name_idx</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">col_names</span><span class="p">)):</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">categoric_lbls</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
            <span class="n">derived_colnames</span> <span class="o">=</span> <span class="n">get_derived_colnames</span><span class="p">(</span><span class="s2">&quot;labelBinarizer(&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">col_names</span><span class="p">[</span><span class="n">col_name_idx</span><span class="p">]),</span>
                                                    <span class="p">[</span><span class="n">categoric_lbls</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]],</span> <span class="s2">&quot;)&quot;</span><span class="p">)</span>

            <span class="n">norm_descr</span> <span class="o">=</span> <span class="n">pml</span><span class="o">.</span><span class="n">NormDiscrete</span><span class="p">(</span><span class="n">field</span><span class="o">=</span><span class="nb">str</span><span class="p">(</span><span class="n">col_names</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]),</span> <span class="n">value</span><span class="o">=</span><span class="nb">str</span><span class="p">(</span><span class="n">categoric_lbls</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]))</span>
            <span class="n">derived_flds</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pml</span><span class="o">.</span><span class="n">DerivedField</span><span class="p">(</span><span class="n">NormDiscrete</span><span class="o">=</span><span class="n">norm_descr</span><span class="p">,</span>
                                                 <span class="n">name</span><span class="o">=</span><span class="n">derived_colnames</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span>
                                                 <span class="n">optype</span><span class="o">=</span><span class="n">OPTYPE</span><span class="o">.</span><span class="n">CATEGORICAL</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                                                 <span class="n">dataType</span><span class="o">=</span><span class="n">DATATYPE</span><span class="o">.</span><span class="n">DOUBLE</span><span class="o">.</span><span class="n">value</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">derived_colnames</span> <span class="o">=</span> <span class="n">get_derived_colnames</span><span class="p">(</span><span class="s2">&quot;labelBinarizer(&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">col_names</span><span class="p">[</span><span class="n">col_name_idx</span><span class="p">]),</span>
                                                    <span class="n">categoric_lbls</span><span class="p">,</span> <span class="s2">&quot;)&quot;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">attribute_name</span> <span class="ow">in</span> <span class="n">col_names</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">class_name</span><span class="p">,</span> <span class="n">class_idx</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">categoric_lbls</span><span class="p">,</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">categoric_lbls</span><span class="p">))):</span>
                    <span class="n">norm_descr</span> <span class="o">=</span> <span class="n">pml</span><span class="o">.</span><span class="n">NormDiscrete</span><span class="p">(</span><span class="n">field</span><span class="o">=</span><span class="nb">str</span><span class="p">(</span><span class="n">attribute_name</span><span class="p">),</span> <span class="n">value</span><span class="o">=</span><span class="nb">str</span><span class="p">(</span><span class="n">class_name</span><span class="p">))</span>
                    <span class="n">derived_flds</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                        <span class="n">pml</span><span class="o">.</span><span class="n">DerivedField</span><span class="p">(</span><span class="n">NormDiscrete</span><span class="o">=</span><span class="n">norm_descr</span><span class="p">,</span>
                                         <span class="n">name</span><span class="o">=</span><span class="n">derived_colnames</span><span class="p">[</span><span class="n">class_idx</span><span class="p">],</span>
                                         <span class="n">optype</span><span class="o">=</span><span class="n">OPTYPE</span><span class="o">.</span><span class="n">CATEGORICAL</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                                         <span class="n">dataType</span><span class="o">=</span><span class="n">DATATYPE</span><span class="o">.</span><span class="n">DOUBLE</span><span class="o">.</span><span class="n">value</span><span class="p">))</span>

    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_fld&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">derived_flds</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_col_names&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">derived_colnames</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;pp_feat_class_lbl&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">categoric_lbls</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;pp_feat_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">col_names</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

    <span class="k">return</span> <span class="n">pp_dict</span></div>


<div class="viewcode-block" id="one_hot_encoder"><span class="k">def</span> <span class="nf">one_hot_encoder</span><span class="p">(</span><span class="n">trfm</span><span class="p">,</span> <span class="n">col_names</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Generates pre-processing elements for Scikit-Learn&#39;s OneHotEncoder</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    trfm :</span>
<span class="sd">        Contains the Sklearn&#39;s One hot encoder preprocessing instance.</span>
<span class="sd">    col_names : list</span>
<span class="sd">        Contains list of feature/column names.</span>
<span class="sd">        The column names may represent the names of preprocessed attributes.</span>

<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    pp_dict : dictionary</span>
<span class="sd">        Returns a dictionary that contains attributes related to Label Binarizer preprocessing.</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">derived_flds</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
    <span class="n">derived_colnames</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
    <span class="n">pp_dict</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
    <span class="n">categoric_lbls</span> <span class="o">=</span> <span class="n">trfm</span><span class="o">.</span><span class="n">categories_</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
    <span class="k">for</span> <span class="n">col_name_idx</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">col_names</span><span class="p">)):</span>
        <span class="n">derived_colnames</span> <span class="o">=</span> <span class="n">get_derived_colnames</span><span class="p">(</span><span class="s2">&quot;oneHotEncoder(&quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">col_names</span><span class="p">[</span><span class="n">col_name_idx</span><span class="p">]),</span>
                                                <span class="n">categoric_lbls</span><span class="p">,</span> <span class="s2">&quot;)&quot;</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">attribute_name</span> <span class="ow">in</span> <span class="n">col_names</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">class_name</span><span class="p">,</span> <span class="n">class_idx</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">categoric_lbls</span><span class="p">,</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">categoric_lbls</span><span class="p">))):</span>
                <span class="n">norm_descr</span> <span class="o">=</span> <span class="n">pml</span><span class="o">.</span><span class="n">NormDiscrete</span><span class="p">(</span><span class="n">field</span><span class="o">=</span><span class="nb">str</span><span class="p">(</span><span class="n">attribute_name</span><span class="p">),</span> <span class="n">value</span><span class="o">=</span><span class="nb">str</span><span class="p">(</span><span class="n">class_name</span><span class="p">))</span>
                <span class="n">derived_flds</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                    <span class="n">pml</span><span class="o">.</span><span class="n">DerivedField</span><span class="p">(</span><span class="n">NormDiscrete</span><span class="o">=</span><span class="n">norm_descr</span><span class="p">,</span>
                                     <span class="n">name</span><span class="o">=</span><span class="n">derived_colnames</span><span class="p">[</span><span class="n">class_idx</span><span class="p">],</span>
                                     <span class="n">optype</span><span class="o">=</span><span class="n">OPTYPE</span><span class="o">.</span><span class="n">CATEGORICAL</span><span class="o">.</span><span class="n">value</span><span class="p">,</span>
                                     <span class="n">dataType</span><span class="o">=</span><span class="n">DATATYPE</span><span class="o">.</span><span class="n">DOUBLE</span><span class="o">.</span><span class="n">value</span><span class="p">))</span>

    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_fld&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">derived_flds</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;der_col_names&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">derived_colnames</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;pp_feat_class_ohe&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">categoric_lbls</span>
    <span class="n">pp_dict</span><span class="p">[</span><span class="s1">&#39;pp_feat_name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">col_names</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

    <span class="k">return</span> <span class="n">pp_dict</span></div>
</pre></div>

           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2020, maintainer@nyoka.org

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>